from django.db import models

# Create your models here.
from django.utils import timezone

from common.models import Person


class Work(models.Model):
    WEEKDAY = (
        (0, "工作日"),
        (1, "周末"),
        (2, "法定节假日"),
    )

    name = models.ForeignKey(to=Person, verbose_name="姓名", on_delete=models.CASCADE, related_name="per_work")
    time_long = models.DecimalField(verbose_name='加班时长', default=0, max_digits=99999, decimal_places=2)
    work_time = models.DateField(verbose_name="加班日期", default=timezone.now)
    time = models.DateTimeField(verbose_name="记录时间", auto_now=True)
    week_today = models.IntegerField(verbose_name="工作日", choices=WEEKDAY, default=0)

    # def week_tody(self):
    #     owd = self.work_time.isoweekday()
    #     return "周末" if owd == 6 or owd == 7 else "工作日"
    # week_tody.__name__ = "是否工作日"

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ('-pk',)
        verbose_name = '加班时长'
        verbose_name_plural = verbose_name

